
#pragma once

#include "HRKNodeAnim.h"
#include "HRKNodeTable.h"

class CHrkMesh;
class CHrkMaterial;
class CHrkSkin;
class CHrkNodeAnim;


class CHrkNodeData
{
public:
	CHrkNodeData()
	{
		m_pGameNode = NULL;
		m_bBone = false;
	}

	IGameNode* m_pGameNode;
	TSTR m_sName;
	bool m_bBone;
	
};

class CHrkScene
{
public:
	CHrkScene();
	~CHrkScene();
public:
	typedef enum
	{
		PT_TRILIST,
		PT_TRIFAN,
		PT_TRISTRIP
	}PRIM_TYPE;

	void ExportGameScene( CHrkStream& os,bool bExportSelected , INode * pRootNode);

	void ExportGameNode1( CHrkStream& os,IGameNode* pNode );
	void ExportGameScene1(CHrkStream& os,bool bExportSelected , INode * pRootNode);

	void ExportGameAnim( CHrkStream& os,bool bExportSelected );

	void ExportGameNode( CHrkStream& os,IGameNode* pNode );

	void ProcessGameNode( CHrkStream& os,IGameNode* pNode );
	void CollectGameSkin();
	
	void AddGameSkin( IGameNode* pGameNode );
	void CleanGameSkin();

	IBipMaster* FindBipedMaster();
	IBipedExport* FindBipedInterface();
	
	void CollectGameMaterial();
	void ProcessGameMaterial( CHrkStream& os );
	void CleanGameMaterial();

	void CollectGameNode();
	void CleanGameNode();

	void CollectGameAnim();
	void ProcessGameAnim( CHrkStream& os,CHrkStream& log );
	void CleanGameAnim();

	void ProcessGameMesh( CHrkStream& os,IGameNode* pNode,IGameObject* pObject);
	void ProcessMaxMesh( CHrkMesh& myMesh,CHrkStream& os,IGameNode* pNode,IGameObject* pObject);
	void ProcessGameBone(CHrkStream& os,IGameNode* pNode,IGameObject* pObject);
	int FindMatId( IGameMaterial* pMaterial );
	IGameMaterial* FindStdMaterial( const TCHAR* sName );
	IGameSkin* FindGameMeshSkin( IGameNode* pGameNode,IGameObject* pGameObject );
	bool IsSkinBoneNode( IGameNode* pNode );

	CHrkStream m_log;

	bool m_bEnterFigureMode;

	IGameScene* m_pIGame;
	IGameConversionManager* m_pConvMan;

	Tab<CHrkMaterial*> m_sceneMatTab;
	
	std::vector<CHrkNodeAnim*> m_animTab;
	CHrkNodeTable m_nodeTab;

	std::vector<CHrkSkin*> m_skinVec;

	PRIM_TYPE m_OutputPrimType;

	static BOOL m_bExportAnim;
	static BOOL m_bFullSample;
	BOOL m_bHierarky;

	IGameConversionManager::CoordSystem m_eCoordSystem;

	std::map<IGameNode*,CHrkNodeData*> m_nodeDataMap;
	void OutputInitBoneNodeTM( CHrkStream &os,IGameNode* pNode );

	void CollectNodeData();
	void OutputPrmFile();
	void AddNodeData(IGameNode* pGameNode);
	CHrkNodeData* FindNodeData(IGameNode* pGameNode);
	void CleanNodeData();

	bool GetInitBoneMatrix(IGameNode* pNode,GMatrix& mat);
	bool GetInitBoneMatrix(IGameNode* pNode,Matrix3&mat,bool bObjOffset = false);

	void GetInitNodeMatrix( IGameNode* pNode,GMatrix& mat );
	bool IsTopLevelNode( IGameNode* pNode );

	bool BipedGetInitNodeMatrixWorld( IBipedExport*bip,IGameNode* pNode,GMatrix& mat );
	bool BipedGetInitNodeMatrix( IBipedExport*bip,IGameNode* pNode,GMatrix& mat );
	bool IsBoneNode( IGameNode* pNode );

	void AddNodeVec( std::vector<IGameNode*>& nodeVec,IGameNode* pNode);

	IBipedExport* m_BipedInterface;
	IBipMaster* m_BipedMaster;
};